<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>推荐管理</title>
<link rel="stylesheet" type="text/css"
    href="../../js/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
    href="../../js/easyui/themes/icon.css">
<script type="text/javascript" src="../../js/easyui/jquery-1.7.1.min.js"></script>
<script type="text/javascript"
    src="../../js/easyui/jquery.easyui.min.js"></script>
<script>
function createReommend() {
    $("#recommendTextForm").form('submit', {
        url: "add_or_update_recommend_text.action",
        onSubmit:function() {
            return $(this).form('validate');
        },
        success:function(data) {
            $('#recommendTextsGrid').datagrid('reload');
            closeReommendForm();
        }
    });
}

function closeReommendForm() {
    $('#recommendTextForm').form('clear');
    $('#itemEditorDialog').dialog('close');
}


function addReommend() {
    $('#recommendTextForm').form('load', {
        'recommendText.id':-1
    });
    $('#itemEditorDialog').show();
    $('#itemEditorDialog').dialog({
        title:'添加推荐',
        modal:true
    });
}

function editReommend() {
    var node = $('#recommendTextsGrid').datagrid('getSelected');
    var rows = $('#recommendTextsGrid').datagrid('getSelections');

    if (rows.length != 1) {
        $.messager.alert('警告', '请选择一条记录!', 'warning');
        return;
    }

    $('#recommendTextForm').form('load', {
        'recommendText.id':node.id,
        'recommendText.name':node.name,
        'recommendText.link':node.link
    });

    $('#itemEditorDialog').show();
    $('#itemEditorDialog').dialog({
        name:'编辑',
        modal:true
    });
}

function deleteReommend() {
    var node = $('#recommendTextsGrid').datagrid('getSelected');
    var rows = $('#recommendTextsGrid').datagrid('getSelections');

    if (rows.length != 1) {
        $.messager.alert('警告', '请选择一条记录!', 'warning');
        return;
    }
    $('#recommendTextForm').form('load', {
        'recommendText.id':node.id,
        'recommendText.name':node.name
    });
    $.messager.confirm('确认','确认要删除吗?',function(fn){   
        if (fn){            
            $("#recommendTextForm").form('submit', {
                url: "delete_recommendText.action",
                success:function(data) {
                    $('#recommendTextsGrid').datagrid('reload');
                }
            });   
        }   
    });  
}

$(function() {
    $('#recommendTextsGrid').datagrid( {
            url : 'find_recommend_text.action',
            idField:'id',
            rownumbers:true,
            columns : [ [ 
                {field: 'id', title: '序号', width: 80},
                {field: 'name', title: '名字', width: 100},
                {field: 'link', title: '链接', width: 300}
            ] ],
            toolbar:[
                        {
                            text:'添加',
                            iconCls:'icon-add',
                            handler:function() {
                                addReommend();
                            }
                        },
                        {
                            text:'编辑',
                            iconCls:'icon-edit',
                            handler:function() {
                                editReommend();
                            }
                        },
                        '-',
                        {
                            text:'删除',
                            iconCls:'icon-remove',
                            handler:function() {
                                deleteReommend();
                            }
                        }
                   ]
    });
});
</script>
</head>
<body>

<h1>DataGrid</h1>
<table id="recommendTextsGrid"></table>
<div id="itemEditorDialog" icon="icon-save" title="管理"
    style="height: 400; width: 400; display: none; padding: 5px;">
<form method="post" id="recommendTextForm" name="recommendTextForm">
<table>
    <tr>
        <td><label>名称：</label></td>
        <td><input class="easyui-validatebox" id="name"
            name="recommendText.name" /></td>
    </tr>
    <tr>
        <td><label>链接：</label></td>
        <td><input class="easyui-validatebox" id="link"
            name="recommendText.link"/></td>
    </tr>
</table>
<div class="toolbar" style="padding: 10px;"><a href="#"
    onclick="createReommend()" class="easyui-linkbutton" iconCls="icon-ok">确定</a>
<a href="#" onclick="closeReommendForm()" class="easyui-linkbutton"
    iconCls="icon-cancel">取消</a></div>
<input type="hidden" name="recommendText.id" value="-1" /></form>
</div>
</body>
</html>